<%@page import="search.DealSearchData"%>
<%@page import="admin.data.CategoryData"%>
<%@page import="models.CategoryModel"%>
<%@page import="java.util.List"%>
<%@page import="admin.data.DealData"%>
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="models.DealModel"%>
<%@page import="helpers.UrlHelper"%>
<%@page import="java.util.ArrayList"%>
<%	
	DealSearchData dealSearch = (DealSearchData) request.getAttribute("dealSearch");	
	List<DealModel> deals = dealSearch.getListResult();
	String url = (String)request.getAttribute("url");
	String parameter = "";
	String dealId = "";
	String name = "";
	String category = "";
	String status = "";
	if(request.getAttribute("dealId")!=null&&!request.getAttribute("dealId").toString().isEmpty()){
		dealId = (String)request.getAttribute("dealId");
		parameter += "&dealId=" + dealId;
	}	
	if(request.getAttribute("name")!=null&&!request.getAttribute("name").toString().isEmpty()){
		name = (String)request.getAttribute("name");
		parameter += "&name=" + name;
	}
	if(request.getAttribute("category")!=null&&!request.getAttribute("category").toString().isEmpty()){
		category = (String)request.getAttribute("category");
		parameter += "&category=" + category;
	}		
	if(request.getAttribute("status")!=null&&!request.getAttribute("status").toString().isEmpty()){
		status = (String)request.getAttribute("status");
		parameter += "&status=" + status;
	}	
%>

<jsp:include page="/admin/layouts/header.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>
<script type="text/javascript" src="/admin/js/list_deal.js"></script>
<script type="text/javascript" src="/admin/js/list_form.js"></script>
<script type="text/javascript">
<!--
var server = "<%=UrlHelper.getServerUrl(request)%>";
//-->
</script>
        <div class="maincontent noright">
        	<div class="maincontentinner">
            	
                <ul class="maintabmenu">
                	<li><a href="/admin/deal/manage">Thống kê Deal</a></li>
                	<li class="current"><a href="/admin/deal/list">Quản lý Deal</a></li>
                	<li><a href="/admin/deal/add">Tạo mới Deal</a></li>
                	<li><a href="/admin/ads/right">Quản lý Deal Quảng cáo</a></li>
                </ul><!--maintabmenu-->
                
                <div class="content">
                	<form class="stdform" action="/admin/deal/list" method="post" id="dealDearchForm">
	                    <div class="one_half">      
	                    	<p>
	                    		<label>Mã Deal : </label>
	                            <span class="field"><input type="text" name="dealId" class="longinput" value="<%=(dealId!=null&&!dealId.isEmpty())?dealId:""%>"/></span>                
	                    	</p>
	                    	<p>
	                    		<label>Tên Deal : </label>
	                    		<span class="field"><input type="text" name="name" class="longinput" value="<%=(name!=null&&!name.isEmpty())?name:""%>"/></span>                  
	                    	</p>       
	                    	<p>
                    		<label>Danh mục : </label>
	                            <select id="category" name="category" class="smallinput">
	                            	<option value="all">(Tất cả)</option>	
	                            	<%
	                            		for(CategoryModel cate: CategoryData.getAll()){
	                            	%>
										<option value="<%=cate.getCategoryId() %>" <%=(category.equalsIgnoreCase(cate.getCategoryId()))?"selected":""%>><%=cate.getName() %></option>								
									<%
	                            		}
									%>
								</select>                              
	                    	</p>                       	           
							<p>
	                    		<label>Trạng thái : </label>
	                             <span class="field">
		                            <select name="status">
		                            	<option value="">Tất cả trạng thái</option>
		                            	<option value="0" <%=(status!=null&&status.equals("0"))?"selected":"" %>>Chưa kích hoạt</option>
		                                <option value="1" <%=(status!=null&&status.equals("1"))?"selected":"" %>>Chờ kích hoạt</option>
		                                <option value="2" <%=(status!=null&&status.equals("2"))?"selected":"" %>>Đang chạy</option>
		                                <option value="3" <%=(status!=null&&status.equals("3"))?"selected":"" %>>Kết thúc</option>
		                                <option value="4" <%=(status!=null&&status.equals("4"))?"selected":"" %>>Đã khoá</option>
		                                <option value="5" <%=(status!=null&&status.equals("5"))?"selected":"" %>>Đã hoàn thành</option>	                            
		                            </select>
	                            </span>                                
	                    	</p>                           	                    	                    	          						                     	                        
	                    	<p class="stdformbutton">
		                     	<input type="submit" class="reset radius2" value="Tìm kiếm">
		                        <input type="reset" class="reset radius2" value="Làm lại" id="btnReset">
		                     </p>                  	     	                    	        	                                        
	                    </div><!--one_half-->                                               	
                   </form> 
                   <br clear="all" /><br />    
               		<jsp:include page="/admin/elements/message.jsp"/>
                	<div class="contenttitle radiusbottom0">
	                	<h2 class="table"><span>Danh sách Deal</span></h2>
	                </div>
	                
	                <div class="tableoptions">
	                    <select class="radius3 action-value">
	                    	<option value="0">Chọn thao tác</option>
	                    	<option value="specialAdvertising">Chọn Deal làm quảng cáo trang chủ</option>		    
	                    	<option value="topAdversiting">Chọn Deal làm quảng cáo menu top</option>
	                    	<option value="rightAdversiting">Chọn Deal làm quảng cáo menu right</option>		
							<!-- <option value="delete">Xóa tất cả Deal đã chọn</option>		  -->                   	                        	                      
	                    </select> &nbsp;
	                    <button class="radius3 apply-change">Áp dụng</button>
	                </div>
	                
	                <table cellspacing="0" cellpadding="0" border="0" class="stdtable stdtablecb" id="list-table">
	                    <colgroup>
	                        <col class="con0">
	                        <col class="con1">
	                        <col class="con0">
	                        <col class="con1">
	                        <col class="con0">
	                        <col class="con1">
	                    </colgroup>
	                    <thead>
	                        <tr>
	                        	<th class="head0"><span class="checkbox"><input type="checkbox" class="checkall"></span></th>
	                            <th class="head1">Mã Deal</th>
	                            <th class="head0">Tên Deal</th>
	                            <th class="head1">Mã hợp đồng</th>
	                            <th class="head0">Tên sale</th>
	                            <th class="head1">Trạng thái</th>
	                            <th class="head1">Thao tác</th>
	                        </tr>
	                    </thead>	                   
	                    <tbody>
	                    	<% for (int i = 0; i < deals.size(); i++) { %>
	                        <tr>
	                        	<td class="center"><span class="checkbox"><input type="checkbox" value="<%=deals.get(i).getDealId()%>"></span></td>
								<td class="center"><%=deals.get(i).getDealId() %></td>
	                            <td>
	                            	<%=deals.get(i).getShortName()%>
	                            	<%
	                            		if(deals.get(i).getStatus()==1||deals.get(i).getStatus()==0){
	                            			%>
	                            			<a title="Xem Deal" href="/<%=deals.get(i).getDealId()%>/<%=deals.get(i).getAlias() %>.demo" target="blank">
			                            	(Link demo)
			                            	</a>	
	                            			<%
	                            		}else{
	                            	%>    
	                            	<a title="Xem Deal" href="/<%=deals.get(i).getDealId()%>/<%=deals.get(i).getAlias() %>.html" target="blank">
	                            		(Xem)
	                            	</a>	
	                            	<%
	                            		}
	                            	%>
	                            	                        
	                            </td>	
	                            <td><%=deals.get(i).getContractCode() %></td>
	                            <td><%=deals.get(i).getUsername() %></td>
	                            <td class="center">
	                            	<%
									switch (deals.get(i).getStatus()) {
										case 0: 
											%>Chưa kích hoạt<%
											break;
										case 1:
											%>Đang kích hoạt<%
											break;
										case 2:
											%>Đang chạy<%
											break;
										case 3:
											%>Kết thúc<%
											break;
										case 4:
											%>Đã khóa<%
											break;
										case 5:
											%>Hoàn thành<%
											break;
										default:
											%>Chưa kích hoạt<%
											break;											
									}
									%>
	                            </td>
	                            <td class="center">
									<a title="Edit Link" href="/admin/deal/edit?id=<%=deals.get(i).getDealId()%>" class="edit">
										Sửa
									</a><%-- &nbsp;|							
									<a title="Remove Link" href="<%=deals.get(i).getDealId()%>" id="action_del" class="delete_button">
										Xoá
									</a> --%>
								</td>
	                        </tr>
	                        <% } %>
	                    </tbody>
	                </table>
	                
	                <!-- paginate -->
	                <div class="dataTables_paginate paging_full_numbers" id="dyntable_paginate">
	                 	<a class="paginate_button"  href="/admin/deal/add">Thêm mới Deal</a>
	                	<% if (dealSearch.isHasPreviousPage()) { %>
							<a class="previous paginate_button" id="dyntable_previous" href="<%=url%>?page=<%=dealSearch.getPage()-1%>">Trước</a>
						<% } else { %>
							<span class="previous paginate_button paginate_button_disabled" id="dyntable_previous">Trước</span>
						<% } %>
						<% if (dealSearch.isHasNextPage()) { %>
							<a class="next paginate_button" id="dyntable_next"  href="<%=url%>?page=<%=dealSearch.getPage()+1%>">Sau</a>
						<% } else { %>
							<span class="next paginate_button paginate_button_disabled" id="dyntable_next">Sau</span>
						<% } %>
	                </div>
                </div><!--content-->
                
            </div><!--maincontentinner-->
            
            <jsp:include page="/admin/elements/copyright.jsp">
            	<jsp:param name="language" value="1" />
			</jsp:include>
            
        </div><!--maincontent-->
        
<jsp:include page="/admin/layouts/footer.jsp">
    <jsp:param name="language" value="1" />
</jsp:include>